package classroom;

import adapters.AdapterClassroom;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

import com.project.institute.DAO.InstituteFragmentActivityDAO;
import com.project.trac.R;

import core.modules.Institute;

public class ActivityManager extends InstituteFragmentActivityDAO  {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.student_classroom_manager);
		setTitle("You are now in - " + getSubjectName());
		
		AdapterClassroom ca = new AdapterClassroom(getApplicationContext(), getSupportFragmentManager());
		ViewPager viewpager_ClassroomManager;

		viewpager_ClassroomManager = (ViewPager) findViewById(R.id.viewpager_classroom);

		viewpager_ClassroomManager.setAdapter(ca);
		viewpager_ClassroomManager.setCurrentItem(0);

		viewpager_ClassroomManager.setOnPageChangeListener(new OnPageChangeListener() {

			/* call on the generic_indicators */
			public void onPageSelected(int position) {
				switch (position) {

				case 0:
					findViewById(R.id.generic_tab_first).setVisibility(View.VISIBLE);
					findViewById(R.id.generic_tab_second).setVisibility(View.INVISIBLE);
					findViewById(R.id.generic_tab_third).setVisibility(View.INVISIBLE);
					break;

				case 1:
					findViewById(R.id.generic_tab_first).setVisibility(View.INVISIBLE);
					findViewById(R.id.generic_tab_second).setVisibility(View.VISIBLE);
					findViewById(R.id.generic_tab_third).setVisibility(View.INVISIBLE);
					break;

				case 2:
					findViewById(R.id.generic_tab_first).setVisibility(View.INVISIBLE);
					findViewById(R.id.generic_tab_second).setVisibility(View.INVISIBLE);
					findViewById(R.id.generic_tab_third).setVisibility(View.VISIBLE);
					break;
				}
			}
			/* unused methods */
			public void onPageScrollStateChanged(int position) { }
			public void onPageScrolled(int arg0, float arg1, int arg2) { }
		});

	}

	@Override
	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		Window window = getWindow();
		window.setFormat(PixelFormat.RGBA_8888);
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.student, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case R.id.menu_logout:
	            new Institute().Logout(this);
	            return true;
	        default:
	            return super.onOptionsItemSelected(item);
	    }
	}
}